package com.unbox.generate.util;
import com.unbox.generate.entity.DBInfo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqlConnectionUtil {

    /**
     * 获取数据库链接
     * @param tableInfo
     * @return
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public static Connection getConnection(DBInfo tableInfo) throws SQLException, ClassNotFoundException {
        // 注册 JDBC 驱动
        Class.forName(tableInfo.getMysqlDev());
        Connection connection = DriverManager.getConnection("jdbc:mysql://"+tableInfo.getMysqlUrl()+"/"+tableInfo.getDbName()+"?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true",tableInfo.getUserName(),tableInfo.getPassWord());
        return connection;
    }
}
